package se.opendataexchange.simulator;

import se.opendataexchange.common.AddressValue;

public class MathGenerator extends FunctionGenerator {

	public enum FunctionType{
		SIN,
		COS,
		REST10,
	}
	FunctionType type;
	long tStart;
	long msPeriod = 1000;
	
	public MathGenerator(AddressValue val, long interval, FunctionType type) {
		super(val, interval);
		this.type = type;
		tStart = System.currentTimeMillis();
		msPeriod = interval*100;
	}

	@Override
	protected Object getValue() {
		double seed = (double)((long)(System.currentTimeMillis()-tStart));
		if(type==FunctionType.SIN){
			seed = seed*2*Math.PI/msPeriod;
			return Math.sin(seed);
		}else if(type == FunctionType.COS){
			seed = seed*2*Math.PI/msPeriod;
			return Math.cos(seed);
		}else if(type == FunctionType.REST10){
			return seed%msPeriod;
		}
		return seed%msPeriod;
	}

}
